<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace common\behavior;

use support\bootstrap\Redis;
use Webman\Stomp\Client;

/**
 * 行为扩展：处理event
 */
class WriteEventBehavior
{

    /**
     * 处理记录event log
     * @param $params
     * @throws \Exception
     */
    public function run(&$params)
    {
        APP_DEBUG && trace("push handle request event " . \request()->getBatchNumber(), "DEBUG");
        $batchNumber = \request()->getBatchNumber();
        // 空event
        if (!Redis::lLen($batchNumber)) {
            return;
        }
        // 投递消息
        Client::send('event', build_queue_data_with_xu(["event_data_key" => $batchNumber]));
    }
}
